package com.vf.admin.miaodong.controller;

import com.vf.admin.client.service.AppAuthService;
import com.vf.admin.client.service.AppAuthUserService;
import com.vf.admin.client.service.AppUserService;
import com.vf.admin.client.service.AppVoiceSignatureService;
import com.vf.admin.common.BaseController;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppVoiceSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/after/voicesignature")
public class AfterVoiceSignatureController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    AppAuthService appAuthService;
    @Autowired
    AppAuthUserService appAuthUserService;
    @Autowired
    AppUserService appUserService;
    @Autowired
    AppVoiceSignatureService appVoiceSignatureService;

    @RequestMapping("/list")
    public String list(SplitPageBean splitPageBean) {
        try {

            List<AppVoiceSignature> list = appVoiceSignatureService.page(splitPageBean);
            request.setAttribute("list", list);
            request.setAttribute("splitPage", splitPageBean);
            return this.sucess("/web/after/voicesignature/list");
        } catch (Exception e) {
            return this.error("系统繁忙");
        }
    }

    @RequestMapping("/save")
    @ResponseBody
    public Result save(AppVoiceSignature param) {
        try {
            appVoiceSignatureService.save(param);

            return sucessJSON("success");
        } catch (Exception e) {
            return errorJSON("系统繁忙");
        }
    }

    @RequestMapping("/detail")
    public String detail(Integer id) {
        try {
            AppVoiceSignature voiceSignature = appVoiceSignatureService.get(id);

            request.setAttribute("obj", voiceSignature);
            return this.sucess("/web/after/voicesignature/edit");
        } catch (Exception e) {
            logger.error("获取轮播图异常", e);
            return this.error("系统繁忙");
        }
    }

    @RequestMapping("/del")
    @ResponseBody
    public Result del(Integer id) {
        try {
            appVoiceSignatureService.del(id);
            return this.sucessJSON("删除成功");
        } catch (Exception e) {
            return this.errorJSON("系统繁忙");
        }
    }

    @RequestMapping("/gotoAdd")
    public String gotoAdd() {
        return this.sucess("/web/after/voicesignature/add");
    }
}
